package com.pig4cloud.pigx.contract.api.v1.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.customize.api.annotation.OpenApi;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.contract.api.v1.service.TradeServiceV1;
import com.pig4cloud.pigx.contract.open.api.dto.OpenApiLatelyTradeDTOV1;
import com.pig4cloud.pigx.contract.open.api.dto.OpenApiTradeHistoryDTOV1;
import com.pig4cloud.pigx.contract.open.api.vo.OpenApiLatelyTradeVOV1;
import com.pig4cloud.pigx.contract.open.api.vo.OpenApiTradeHistoryVOV1;
import com.pig4cloud.pigx.user.enums.UserApiKeyEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 开放API - 成交记录 - v1版本
 *
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/contract/trade" )
@Api(value = "api_trade_v1", tags = "开放api-成交记录")
public class TradeControllerV1 {

	private final TradeServiceV1 service;

	/**
	 * 获取近期成交记录
	 * @param dto 请求参数
	 * @return 成交记录
	 */
	@ApiOperation(value = "获取近期成交记录", notes = "获取近期成交记录")
	@SysLog("获取近期成交记录" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@PostMapping("/lately")
	public R<List<OpenApiLatelyTradeVOV1>> getLatelyTrade(@RequestBody OpenApiLatelyTradeDTOV1 dto) {
		return service.getLatelyTrade(dto);
	}

	/**
	 * 获取历史成交记录
	 * @param dto 请求参数
	 * @return 成交记录
	 */
	@ApiOperation(value = "获取历史成交记录", notes = "获取历史成交记录")
	@SysLog("获取历史成交记录" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@PostMapping("/history")
	public R<List<OpenApiLatelyTradeVOV1>> getHistoryTrade(@RequestBody OpenApiLatelyTradeDTOV1 dto) {
		return service.getLatelyTrade(dto);
	}

	/**
	 * 获取用户历史成交记录
	 * @param dto 请求参数
	 * @return 成交记录
	 */
	@ApiOperation(value = "获取用户历史成交记录", notes = "获取用户历史成交记录")
	@SysLog("获取用户历史成交记录" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@PostMapping("/user/history")
	public R<Page<OpenApiTradeHistoryVOV1>> getUserTradeHistory(@RequestBody OpenApiTradeHistoryDTOV1 dto){
		return service.getUserTradeHistory(dto);
	}

}
